export function ListReducer(state = {
  id: 1, users: [
    { uid: 1, uname: '刘小杰', uage: 18, usex: '女' }
  ]
}, action) {
  switch (action.type) {
    case 'ADDUSER':
      console.log(action.payload)
      // 添加用户：
      let id = state.id + 1; // 给uid属性，做主键子增长。

      let obj = { uid: id, ...action.payload }
      state.users.push(obj);

      return { id, 'users': [...state.users] };

    case 'DELUSER':
      // 不保留id相同的，
      let arr = state.users.filter(el => el.id !== action.payload)
      return { ...state, users: arr };

    case 'UPDATEUSER':
      let temp = JSON.parse(JSON.stringify(state.users));
      temp.forEach(el => {
        if (el.uid === action.payload.uid) {
          el = { ...el, ...action.payload }
        }
      });
      return { ...state, users: temp }

    default:
      return state;
  }
}